Skip to content

feat(langchain) GenAI semconv compliance#3822

Closed
max-deygin-traceloop wants to merge 7 commits intomax/tlp-1925-python-sdk-otel-semantic-conventionfrom
max/tlp-1927-langchain-instrumentation
Closed

feat(langchain) GenAI semconv compliance#3822
max-deygin-traceloop wants to merge 7 commits intomax/tlp-1925-python-sdk-otel-semantic-conventionfrom
max/tlp-1927-langchain-instrumentation

Conversation

@max-deygin-traceloop
Copy link
Copy Markdown
Contributor

Migrate LangChain instrumentation to OTel GenAI semconv

Aligns the LangChain instrumentation with the upstream OpenTelemetry GenAI semantic
conventions.

Changes:

  • Replace all SpanAttributes.LLM_* constants with upstream
    GenAIAttributes.GEN_AI_* equivalents
  • Migrate flat gen_ai.prompt.{i}.* / gen_ai.completion.{i}.* attributes to
    gen_ai.input.messages / gen_ai.output.messages JSON arrays (set_llm_request,
    set_chat_request, set_chat_response)
  • Migrate flat gen_ai.tool.definitions.{i}.* attributes to gen_ai.tool.definitions
    JSON array
  • Replace _set_chat_tool_calls (flat span attrs) with _build_tool_calls_list
    (returns list for embedding in JSON)
  • Fix double-set gen_ai.operation.name bug in callback_handler.py
  • Fix vendor detection casing: "Anthropic""anthropic" to match OTel semconv
  • Update all affected tests to parse gen_ai.input.messages /
    gen_ai.output.messages JSON arrays

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 18, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c8ac70f-7754-4197-a8e2-0aa0cdc9fc67

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch max/tlp-1927-langchain-instrumentation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

@max-deygin-traceloop max-deygin-traceloop changed the title Max/tlp 1927 langchain instrumentation feat(langchain) GenAI semconv compliance Mar 18, 2026
@max-deygin-traceloop max-deygin-traceloop force-pushed the max/tlp-1925-python-sdk-otel-semantic-convention branch from 740ee81 to 6401889 Compare March 18, 2026 11:06
@max-deygin-traceloop max-deygin-traceloop force-pushed the max/tlp-1927-langchain-instrumentation branch 2 times, most recently from 072b0ac to 1400d4e Compare March 18, 2026 14:12
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

@max-deygin-traceloop max-deygin-traceloop force-pushed the max/tlp-1927-langchain-instrumentation branch 3 times, most recently from 35fa2f9 to 63b8553 Compare March 18, 2026 14:54

# Record token usage metrics
vendor = span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM, "Langchain")
vendor = span.attributes.get(GenAIAttributes.GEN_AI_SYSTEM, "langchain")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@max-deygin-traceloop max-deygin-traceloop force-pushed the max/tlp-1927-langchain-instrumentation branch from 63b8553 to aadef1d Compare March 19, 2026 14:32
max-deygin-traceloop and others added 7 commits March 19, 2026 20:37
)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: OzBenSimhon <168641541+OzBenSimhonTraceloop@users.noreply.github.com>
Co-authored-by: Gal Kleinman <33281963+galkleinman@users.noreply.github.com>
…→ GEN_AI_

- Replace SpanAttributes.LLM_REQUEST_FUNCTIONS with GenAIAttributes.GEN_AI_TOOL_DEFINITIONS
- Replace SpanAttributes.LLM_REQUEST_TYPE with GenAIAttributes.GEN_AI_OPERATION_NAME
- Replace SpanAttributes.LLM_USAGE_TOTAL_TOKENS with SpanAttributes.GEN_AI_USAGE_TOTAL_TOKENS
- Update test_llms.py, test_tool_calls.py, test_langgraph.py accordingly
- Add test_semconv_compliance.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nitions to JSON array

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace flat gen_ai.prompt.{i}.* attributes with GEN_AI_INPUT_MESSAGES JSON array
- Replace flat gen_ai.completion.{i}.* attributes with GEN_AI_OUTPUT_MESSAGES JSON array
- Convert _set_chat_tool_calls (flat span attrs) to _build_tool_calls_list (returns list)
- Fix vendor_detection: "Anthropic" → "anthropic" to match OTel semconv lowercase
- Update all affected tests to parse GEN_AI_INPUT/OUTPUT_MESSAGES JSON arrays

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…emove debug print

- vendor_detection.py: use canonical GenAISystem string values for all vendors
  (AWS → aws.bedrock, HuggingFace → hugging_face, Google → google, Azure → az.ai.openai,
   Cohere → cohere, Ollama → ollama, Together → together_ai, Replicate → replicate,
   Fireworks → fireworks, Groq → groq, MistralAI → mistral_ai)
- span_utils.py: remove debug print() from production exception handler
- tests: update GEN_AI_SYSTEM assertions to match new lowercase values

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ck, add vendor unit tests

- vendor_detection.py: Google/Vertex AI → "gcp.gen_ai" (matches GenAISystem.GOOGLE)
- vendor_detection.py: both fallback returns "Langchain" → "langchain" (matches GenAISystem.LANGCHAIN)
- callback_handler.py: two GEN_AI_SYSTEM default fallbacks "Langchain" → "langchain"
- span_utils.py: GEN_AI_SYSTEM default fallback "Langchain" → "langchain"
- tests: add parameterized test_vendor_detection.py covering all 13 vendors + default fallback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@max-deygin-traceloop max-deygin-traceloop force-pushed the max/tlp-1927-langchain-instrumentation branch from aadef1d to 71a5029 Compare March 22, 2026 08:20
@max-deygin-traceloop max-deygin-traceloop deleted the branch max/tlp-1925-python-sdk-otel-semantic-convention March 22, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants